package com.szxx.suit;

import com.szxx.domain.Card;

/**
 * 牌数量排序辅助 <br>
 *
 * @author Ambrose
 */
public class SortCard implements Comparable<SortCard> {

	public Card card;
	
	private DdzAnalysisResult result;
	
	public SortCard(Card card, DdzAnalysisResult result) {
		this.card = card;
		this.result = result;
	}

	/**
	 * 数量多的排前面 比如 344442 --> 444432
	 */
	@Override
	public int compareTo(SortCard o) {
		if (card.getValue() == result.getSortFirstValue() && o.card.getValue() == result.getSortFirstValue()) {
			if (getCount() > o.getCount()) {
				return -1;
			} else if (this.getCount() < o.getCount()) {
				return 1;
			} else {
				return card.compareWithShapeTo(o.card);
			}
		} else if (card.getValue() == result.getSortFirstValue()) {
			return -1;
		} else if (o.card.getValue() == result.getSortFirstValue()) {
			return 1;
		} else {
			if (getCount() > o.getCount()) {
				return -1;
			} else if (this.getCount() < o.getCount()) {
				return 1;
			} else {
				return card.compareWithShapeTo(o.card);
			}
		}
	}

	private int getCount() {
		return result.getAllValueCounter().getValueCount(card.getValue());
	}
	
	public Card getCard() {
		return card;
	}

	public void setCard(Card card) {
		this.card = card;
	}

}
